import { defineFakeRoute } from "vite-plugin-fake-server/client";
import { faker } from "@faker-js/faker/locale/zh_CN";

export default defineFakeRoute([
  // 商品分类列表
  {
    url: "/api/goods-category/list",
    method: "post",
    response: () => {
      return {
        success: true,
        code: 200,
        data: {
          list: Array.from({ length: 4 }).map(() => ({
            id: faker.number.int(),
            name: faker.lorem.word(),
            parent_id: faker.number.int(),
            children: Array.from({ length: 2 }).map(() => ({
              id: faker.number.int(),
              name: faker.lorem.word(),
              parent_id: faker.number.int()
            })),
            // image: faker.image.url(),
            sort: faker.number.int(),
            status: faker.number.int(),
            created_at: faker.date.past(),
            updated_at: faker.date.past()
          }))
        },
        msg: "获取列表成功"
      };
    }
  },
  // 添加商品分类
  {
    url: "/api/goods-category/add",
    method: "post",
    response: () => {
      return {
        success: true,
        code: 200,
        data: {},
        msg: "添加成功"
      };
    }
  },
  // 修改商品分类
  {
    url: "/api/goods-category/update",
    method: "post",
    response: () => {
      return {
        success: true,
        code: 200,
        data: {},
        msg: "修改成功"
      };
    }
  },
  // 删除商品分类
  {
    url: "/api/goods-category/delete",
    method: "post",
    response: () => {
      return {
        success: true,
        code: 200,
        data: {},
        msg: "删除成功"
      };
    }
  },
  // 获取商品分类树
  {
    url: "/api/goods-category/tree",
    method: "get",
    response: () => {
      return {
        success: true,
        code: 200,
        data: {
          list: Array.from({ length: 5 }).map(() => ({
            id: faker.number.int(),
            name: faker.lorem.word(),
            parent_id: faker.number.int(),
            children: Array.from({ length: 2 }).map(() => ({
              id: faker.number.int(),
              name: faker.lorem.word(),
              parent_id: faker.number.int()
            })),
            // image: faker.image.url(),
            sort: faker.number.int(),
            status: faker.number.int(),
            created_at: faker.date.past(),
            updated_at: faker.date.past()
          }))
        }
      };
    }
  }
]);
